import { mpjLog } from './../utils/helper/log';
import { Order } from './../models/order';
import { AppStore } from './appStore';
import { Injectable } from '@angular/core';
import { OrderSvr } from './order';
@Injectable()
export class ShellIntegration {
    constructor(private appStore: AppStore) {

    }
    receiveMessage(content, msgId, cb) {
        function reportException(ex) {
            cb(ex.toString(), msgId);
        }
        try {
            const inOrder:Order = JSON.parse(content);
            (inOrder.items||[]).forEach(item=>delete item.isLocalStall);
            return this.appStore.orderStore.actions.addOrder(inOrder).then(() => {
                cb(null, msgId);
            }, reportException);
        } catch (ex) {
            reportException(ex);
            return Promise.reject(ex);
        }
    }
}
